#!/bin/bash

keyid="GOsaPackages"
key="$(sed -n "/\\[$keyid\\]/,\$s/key *= *\(.*\)/\1/p" /etc/gosa-si/server.conf | head -n 1)"
test -z "$key" && {
  echo 2>&1 "Could not read key from section [$keyid] from /etc/gosa-si/server.conf"
  exit 1
}

msg='
<xml>
    <header>new_server</header>    
    <new_server></new_server>
    <source>127.0.0.1:21090</source>
    <target>127.0.0.1:20081</target>
    <key>loco</key>
    <loaded_modules>gosaTriggered</loaded_modules>
    <loaded_modules>siTriggered</loaded_modules>
    <loaded_modules>clMessages</loaded_modules>
    <loaded_modules>server_server_com</loaded_modules>
    <loaded_modules>databases</loaded_modules>
    <loaded_modules>logHandling</loaded_modules>
<client>172.16.2.10:20083,00:50:56:37:63:10</client>
<client>172.16.2.11:20083,00:50:56:37:63:11</client>
<client>172.16.2.12:20083,00:50:56:37:63:12</client>
<client>172.16.2.13:20083,00:50:56:37:63:13</client>
<client>172.16.2.14:20083,00:50:56:37:63:14</client>
<client>172.16.2.15:20083,00:50:56:37:63:15</client>
<client>172.16.2.16:20083,00:50:56:37:63:16</client>
<client>172.16.2.17:20083,00:50:56:37:63:17</client>
<client>172.16.2.18:20083,00:50:56:37:63:18</client>
<client>172.16.2.19:20083,00:50:56:37:63:19</client>
<client>172.16.2.20:20083,00:50:56:37:63:20</client>
<client>172.16.2.21:20083,00:50:56:37:63:21</client>
<client>172.16.2.22:20083,00:50:56:37:63:22</client>
<client>172.16.2.23:20083,00:50:56:37:63:23</client>
<client>172.16.2.24:20083,00:50:56:37:63:24</client>
<client>172.16.2.25:20083,00:50:56:37:63:25</client>
<client>172.16.2.26:20083,00:50:56:37:63:26</client>
<client>172.16.2.27:20083,00:50:56:37:63:27</client>
<client>172.16.2.28:20083,00:50:56:37:63:28</client>
<client>172.16.2.29:20083,00:50:56:37:63:29</client>
<client>172.16.2.30:20083,00:50:56:37:63:30</client>
<client>172.16.2.31:20083,00:50:56:37:63:31</client>
<client>172.16.2.32:20083,00:50:56:37:63:32</client>
<client>172.16.2.33:20083,00:50:56:37:63:33</client>
<client>172.16.2.34:20083,00:50:56:37:63:34</client>
<client>172.16.2.35:20083,00:50:56:37:63:35</client>
<client>172.16.2.36:20083,00:50:56:37:63:36</client>
<client>172.16.2.37:20083,00:50:56:37:63:37</client>
<client>172.16.2.38:20083,00:50:56:37:63:38</client>
<client>172.16.2.39:20083,00:50:56:37:63:39</client>
<client>172.16.2.40:20083,00:50:56:37:63:40</client>
<client>172.16.2.41:20083,00:50:56:37:63:41</client>
<client>172.16.2.42:20083,00:50:56:37:63:42</client>
<client>172.16.2.43:20083,00:50:56:37:63:43</client>
<client>172.16.2.44:20083,00:50:56:37:63:44</client>
<client>172.16.2.45:20083,00:50:56:37:63:45</client>
<client>172.16.2.46:20083,00:50:56:37:63:46</client>
<client>172.16.2.47:20083,00:50:56:37:63:47</client>
<client>172.16.2.48:20083,00:50:56:37:63:48</client>
<client>172.16.2.49:20083,00:50:56:37:63:49</client>
<client>172.16.2.50:20083,00:50:56:37:63:50</client>
<client>172.16.2.51:20083,00:50:56:37:63:51</client>
<client>172.16.2.52:20083,00:50:56:37:63:52</client>
<client>172.16.2.53:20083,00:50:56:37:63:53</client>
<client>172.16.2.54:20083,00:50:56:37:63:54</client>
<client>172.16.2.55:20083,00:50:56:37:63:55</client>
<client>172.16.2.56:20083,00:50:56:37:63:56</client>
<client>172.16.2.57:20083,00:50:56:37:63:57</client>
<client>172.16.2.58:20083,00:50:56:37:63:58</client>
<client>172.16.2.59:20083,00:50:56:37:63:59</client>
<client>172.16.2.60:20083,00:50:56:37:63:60</client>
<client>172.16.2.61:20083,00:50:56:37:63:61</client>
<client>172.16.2.62:20083,00:50:56:37:63:62</client>
<client>172.16.2.63:20083,00:50:56:37:63:63</client>
<client>172.16.2.64:20083,00:50:56:37:63:64</client>
<client>172.16.2.65:20083,00:50:56:37:63:65</client>
<client>172.16.2.66:20083,00:50:56:37:63:66</client>
<client>172.16.2.67:20083,00:50:56:37:63:67</client>
<client>172.16.2.68:20083,00:50:56:37:63:68</client>
<client>172.16.2.69:20083,00:50:56:37:63:69</client>
<client>172.16.2.70:20083,00:50:56:37:63:70</client>
<client>172.16.2.71:20083,00:50:56:37:63:71</client>
<client>172.16.2.72:20083,00:50:56:37:63:72</client>
<client>172.16.2.73:20083,00:50:56:37:63:73</client>
<client>172.16.2.74:20083,00:50:56:37:63:74</client>
<client>172.16.2.75:20083,00:50:56:37:63:75</client>
<client>172.16.2.76:20083,00:50:56:37:63:76</client>
<client>172.16.2.77:20083,00:50:56:37:63:77</client>
<client>172.16.2.78:20083,00:50:56:37:63:78</client>
<client>172.16.2.79:20083,00:50:56:37:63:79</client>
<client>172.16.2.80:20083,00:50:56:37:63:80</client>
<client>172.16.2.81:20083,00:50:56:37:63:81</client>
<client>172.16.2.82:20083,00:50:56:37:63:82</client>
<client>172.16.2.83:20083,00:50:56:37:63:83</client>
<client>172.16.2.84:20083,00:50:56:37:63:84</client>
<client>172.16.2.85:20083,00:50:56:37:63:85</client>
<client>172.16.2.86:20083,00:50:56:37:63:86</client>
<client>172.16.2.87:20083,00:50:56:37:63:87</client>
<client>172.16.2.88:20083,00:50:56:37:63:88</client>
<client>172.16.2.89:20083,00:50:56:37:63:89</client>
<client>172.16.2.90:20083,00:50:56:37:63:90</client>
<client>172.16.2.91:20083,00:50:56:37:63:91</client>
<client>172.16.2.92:20083,00:50:56:37:63:92</client>
<client>172.16.2.93:20083,00:50:56:37:63:93</client>
<client>172.16.2.94:20083,00:50:56:37:63:94</client>
<client>172.16.2.95:20083,00:50:56:37:63:95</client>
<client>172.16.2.96:20083,00:50:56:37:63:96</client>
<client>172.16.2.97:20083,00:50:56:37:63:97</client>
<client>172.16.2.98:20083,00:50:56:37:63:98</client>
<client>172.16.2.99:20083,00:50:56:37:63:99</client>

    <macaddress>00:50:56:37:63:21</macaddress>
</xml>
'

msg="$(go run main/encrypt.go "$key" "$msg")"
test -z "$msg" && exit 1

for i in $(seq 1 10000) ; do echo $i ; echo "$msg" | nc localhost 20081 ; done
